﻿using Jst.Core.Utility;
using Jst.Infrastructure.Caching;
using Jst.Infrastructure.DbFirst;
using Jst.Infrastructure.ObjectMapping;
using Jst.Infrastructure.Redis;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Jst.Infrastructure.Web
{
    public static class InfrastructureWebExtensions
    {
        public static IServiceCollection AddInfrastructure(this IServiceCollection services,
                                                           IHostEnvironment env)
        {
            // 基础配置
            services.AddSingleton(new AppSettingsHelper(env.ContentRootPath));

            //核心服务注册
            services.AddApplicationServices();

            // 缓存
            services.AddMemoryCacheSetup();
            services.AddRedisCacheSetup();

            // 跨域
            services.AddCorsSetup();

            // JWT
            services.AddAuthorizationSetupForAdmin();

            // HttpContext
            services.AddHttpContextSetup();

            // Mapster
            MappingConfig.RegisterMappings();

            //AutoMapper
            services.AddAutoMapper(typeof(InfrastructureWebExtensions).Assembly);

            //实体生成
            services.AddTransient<DbEntityGenerator>();

            return services;
        }


    }

}